﻿using System;
using System.IO;
using EmptyWallGallery.Core;
using EmptyWallGallery.Core.Utilities;

namespace EmptyWallGallery.FrontEnd
{
    public partial class Contact : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "Contact Us - " + Configs.WebTitle;
            Page.MetaDescription = "Contact Us - " + Configs.WebDescription;
        }

        protected void lnkSend_OnClick(object sender, EventArgs e)
        {
            using (var reader = new StreamReader(Configs.FolderSaveData.Replace("Resource","template") + "EmailContent.htm", System.Text.Encoding.UTF8))
            {
                var strBodyMail = string.Format(reader.ReadToEnd(), txtEmail.Text, txtTitle.Text, txtBody.Text);

                SendMail(Configs.WebMasterEmail, "[Thong tin lien he] - " + txtTitle.Text, strBodyMail, Configs.WebReportEmailCc);

                result.InnerHtml = "* Thanks you for contact.";
            }
        }

        public void SendMail(string iTo, string subject, string body, string cc)
        {
            var mailer = new Mail(Configs.SmtpHost, Configs.SmtpUser, Configs.SmtpPass,
                                  Configs.WebMasterEmail);
                mailer.Send(iTo, subject, body, true, cc);    
        }
    }
}